<template>
  <div class="app-container">

    <el-table :key="tableKey" v-loading="listLoading" :data="list" border fit highlight-current-row
      style="width: 100%;">
      <el-table-column label="微信ID" width="300px" align="center">
        <template slot-scope="{row}">
          <span>{{ row.touser }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态码" align="center" width="150px">
        <template slot-scope="{row}">
          <span v-if="row.errcode == 0" class="link-type">
            <el-button type="success">成功</el-button>
          </span>
          <span v-else style="color:#F56C6C">{{ row.errcode }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提示" min-width="110px" align="center">
        <template slot-scope="{row}">
          <span>{{ row.errmsg }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作时间" width="200px" align="center">
        <template slot-scope="{row}">
          <span>{{ row.update_time | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>

    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
      @pagination="getList" />

  </div>
</template>

<script>
import { getSubscribe } from '@/api/subscribe'
import waves from '@/directive/waves' // waves directive
import { parseTime } from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

export default {
  name: 'ComplexTable',
  components: { Pagination },
  directives: { waves },

  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        importance: undefined,
        title: undefined,
        type: undefined,
        sort: '+id'
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      getSubscribe(this.listQuery).then(response => {
        this.list = response.data
        this.total = response.count
        this.listLoading = false
      }).catch(err => {
        this.listLoading = false
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },

  }
}
</script>
